package com.xnyzc.lhy.mis.service.impl.cms.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xnyzc.lhy.common.entity.Qw;
import com.xnyzc.lhy.common.penum.order.EOrderChannelType;
import com.xnyzc.lhy.common.penum.vehicle.ECallVehType;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.DateUtil;
import com.xnyzc.lhy.mis.entity.area.OaSysArea;
import com.xnyzc.lhy.mis.entity.dictionaries.OaSysDict;
import com.xnyzc.lhy.mis.entity.order.OaCOrderPersonal;
import com.xnyzc.lhy.mis.entity.order.OaDOrder;
import com.xnyzc.lhy.mis.entity.order.OaOrderOtherPrice;
import com.xnyzc.lhy.mis.entity.param.order.OaSysOrderDetails;
import com.xnyzc.lhy.mis.entity.result.order.OrderList;
import com.xnyzc.lhy.mis.entity.system.OaSysUser;
import com.xnyzc.lhy.mis.entity.user.OaDUser;
import com.xnyzc.lhy.mis.entity.user.OaDUserInfo;
import com.xnyzc.lhy.mis.entity.vehicle.OaSysVehicle;
import com.xnyzc.lhy.mis.mapper.area.OaSysAreaMapper;
import com.xnyzc.lhy.mis.mapper.dictionaries.OaSysDictMapper;
import com.xnyzc.lhy.mis.mapper.order.OaCOrderPersonalMapper;
import com.xnyzc.lhy.mis.mapper.order.OaOrderOtherPriceMapper;
import com.xnyzc.lhy.mis.mapper.order.OaSysOrderDetailsMapper;
import com.xnyzc.lhy.mis.mapper.system.OaSysUserMapper;
import com.xnyzc.lhy.mis.mapper.user.OaDUserInfoMapper;
import com.xnyzc.lhy.mis.mapper.user.OaDUserMapper;
import com.xnyzc.lhy.mis.mapper.vehicle.OaSysVehicleMapper;
import com.xnyzc.lhy.mis.service.cms.order.CmsOrderInfoExportServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 导出订单接口实现类
 *
 * @author zhaolijie
 * @date
 */
@Slf4j
@Service
public class CmsOrderInfoExportServerImpl implements CmsOrderInfoExportServer {

    @Autowired
    private OaCOrderPersonalMapper oaCOrderPersonalMapper;

    @Autowired
    private OaSysOrderDetailsMapper oaSysOrderDetailsMapper;

    @Autowired
    private OaSysAreaMapper oaSysAreaMapper;

    @Autowired
    private OaSysVehicleMapper oaSysVehicleMapper;

    @Autowired
    private OaSysDictMapper oaSysDictMapper;

    @Autowired
    private OaDUserMapper oaDUserMapper;

    @Autowired
    private OaDUserInfoMapper oaDUserInfoMapper;

    private String dateFormat = "yyyy-MM-dd HH:mm:ss";

    @Autowired
    private OaOrderOtherPriceMapper oaOrderOtherPriceMapper;

    @Autowired
    private OaSysUserMapper oaSysUserMapper;

    /**
     * 设定查询条件
     *
     * @param orderList
     * @return
     */
    public QueryWrapper<OaCOrderPersonal> findCondition(OrderList orderList) {
        QueryWrapper<OaCOrderPersonal> queryWrapper = new QueryWrapper<>();
        // 查询订单
        if (CheckUtil.strIsNotEmpty(orderList.getOrderNo())) {
            queryWrapper.like(OaCOrderPersonal.ORDER_NO, orderList.getOrderNo());
        }
        // 查询城市
        if (CheckUtil.strIsNotEmpty(orderList.getCityId())) {
            queryWrapper.eq(OaCOrderPersonal.CITY_ID, orderList.getCityId());
        }
        // 查询用车类型
        if (CheckUtil.strIsNotEmpty(orderList.getBusinessType())) {
            queryWrapper.eq(OaCOrderPersonal.VEHICLE_TYPE, orderList.getBusinessType());
        }
        // 车辆ID
        if (CheckUtil.objIsNotEmpty(orderList.getVehicleIds())) {
            queryWrapper.in(OaCOrderPersonal.VEHICLE_ID, orderList.getVehicleIds());
        }
        //司机ID
        if (CheckUtil.objIsNotEmpty(orderList.getDirverIds())) {
            queryWrapper.in(OaCOrderPersonal.DRIVER_ID, orderList.getDirverIds());
        }
        // 查询订单状态
        if (CheckUtil.strIsNotEmpty(orderList.getOrderStatus())) {
            queryWrapper.eq(OaCOrderPersonal.ORDER_STATUS, orderList.getOrderStatus());
        }
        // 查询乘车人姓名
        if (CheckUtil.strIsNotEmpty(orderList.getPassengerName())) {
            queryWrapper.like(OaCOrderPersonal.PASSENGER_NAME, orderList.getPassengerName());
        }
        // 查询乘车人手机号
        if (CheckUtil.strIsNotEmpty(orderList.getPassengerPhone())) {
            queryWrapper.like(OaCOrderPersonal.PASSENGER_PHONE, orderList.getPassengerPhone());
        }
        // 是否改价
        if (CheckUtil.strIsNotEmpty(orderList.getIsChangePrice())) {
            queryWrapper.eq(OaCOrderPersonal.IS_CHANGE_PRICE, orderList.getIsChangePrice());
        }
        // 出发地
        if (CheckUtil.strIsNotEmpty(orderList.getStartAddress())) {
            queryWrapper.like(OaCOrderPersonal.START_ADDRESS, orderList.getStartAddress());
        }
        //目的地
        if (CheckUtil.strIsNotEmpty(orderList.getEndAddress())) {
            queryWrapper.like(OaCOrderPersonal.END_ADDRESS, orderList.getEndAddress());
        }
        //有无退款
        if (CheckUtil.strIsNotEmpty(orderList.getIsRefund())) {
            queryWrapper.eq(OaCOrderPersonal.IS_REFUND, orderList.getIsRefund());
        }
        //订单类型
        if (CheckUtil.strIsNotEmpty(orderList.getOrderType())) {
            queryWrapper.eq(OaCOrderPersonal.ORDER_TYPE, orderList.getOrderType());
        }
        //订单来源
        if (CheckUtil.strIsNotEmpty(orderList.getOrderChannel())) {
            queryWrapper.eq(OaCOrderPersonal.ORDER_CHANNEL, orderList.getOrderChannel());
        }
        // 滴滴订单编号
        if (CheckUtil.strIsNotEmpty(orderList.getDidiOrderId())) {
            queryWrapper.eq(OaCOrderPersonal.DIDI_ORDER_ID, orderList.getDidiOrderId());
        }
        // 下单时间
        if (CheckUtil.objIsNotEmpty(orderList.getOrderStartTime())) {
            queryWrapper.between(OaCOrderPersonal.APPOINTMENT, orderList.getOrderStartTime(), orderList.getOrderEndTime());
        }
        queryWrapper.orderByDesc(OaCOrderPersonal.APPOINTMENT);
        return queryWrapper;
    }


    /**
     * 查询城市字典表的数据
     *
     * @param fieldName：字段名称
     * @param inValue：in查询值
     * @return
     */
    private List<OaSysArea> getDictArea(String fieldName, List<String> inValue) {
        QueryWrapper<OaSysArea> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(fieldName, inValue);
        queryWrapper.select(OaSysArea.AD_CODE, OaSysArea.NAME);
        return oaSysAreaMapper.selectList(queryWrapper);
    }

    /**
     * 查询字典表的数据
     *
     * @param fieldName：字段名称
     * @param inValue：in查询值
     * @return
     */
    private List<OaSysDict> getDictList(String fieldName, List<String> inValue) {
        QueryWrapper<OaSysDict> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(fieldName, inValue);
        queryWrapper.select(OaSysDict.LABEL, OaSysDict.VALUE, OaSysDict.TYPE);
        return oaSysDictMapper.selectList(queryWrapper);
    }

    /**
     * 查询第一组字段
     * oa_c_order_personal.order_no,
     * oa_c_order_personal.city_id,
     * oa_c_order_personal.vehicle_type,
     * oa_c_order_personal.vehicle_id,
     * oa_c_order_personal.order_channel,
     * oa_c_order_personal.order_type
     *
     * @return
     */
    @Override
    public List<OrderList> orderInfoGroupOne(OrderList orderList,List<Long> offices) {
        // 返回的结果集
        List<OrderList> resultLists = new ArrayList<>();
        try {
            QueryWrapper<OaCOrderPersonal> queryWrapper = this.findCondition(orderList);
            queryWrapper.select(OaCOrderPersonal.ORDER_NO, OaCOrderPersonal.CITY_ID, OaCOrderPersonal.VEHICLE_TYPE, OaCOrderPersonal.VEHICLE_ID,OaCOrderPersonal.ORDER_CHANNEL,OaCOrderPersonal.ORDER_TYPE);
            queryWrapper.in(OaCOrderPersonal.OFFICE_ID,offices);
            //防止预约时间一致时排序混乱
            queryWrapper.orderByDesc(OaCOrderPersonal.PERSONAL_ID);
            List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryWrapper);

            // 创建系统字典表in查询的List
            List<String> dictValues = new ArrayList<>();
            dictValues.add("require_level");
            // 开始进行系统字典表查询
            List<OaSysDict> dictList = this.getDictList(OaSysDict.TYPE, dictValues);

            // 城市Code集
            List<String> cityCodes = new ArrayList<>();
            // 车辆Code集
            List<String> vehicleIds = new ArrayList<>();

            for (int i = 0; i < oaCOrderPersonals.size(); i++) {
                OrderList orderListBean = new OrderList();
                orderListBean.setOrderNo(oaCOrderPersonals.get(i).getOrderNo());
                orderListBean.setCityId(oaCOrderPersonals.get(i).getCityId() != null ? oaCOrderPersonals.get(i).getCityId() : "");
                orderListBean.setVehicleType(oaCOrderPersonals.get(i).getVehicleType() != null ? String.valueOf(oaCOrderPersonals.get(i).getVehicleType()) : "");
                orderListBean.setVehicleId(oaCOrderPersonals.get(i).getVehicleId() != null ? String.valueOf(oaCOrderPersonals.get(i).getVehicleId()) : "");
                orderListBean.setOrderChannelStr(oaCOrderPersonals.get(i).getOrderChannel() != null ? EOrderChannelType.findById(oaCOrderPersonals.get(i).getOrderChannel()).getValue() : "");
                orderListBean.setOrderTypeStr(oaCOrderPersonals.get(i).getOrderType() != null ? ECallVehType.finaByType(oaCOrderPersonals.get(i).getOrderType()).getValue() : "");
                cityCodes.add(oaCOrderPersonals.get(i).getCityId() != null ? oaCOrderPersonals.get(i).getCityId() : "");
                vehicleIds.add(oaCOrderPersonals.get(i).getVehicleId() != null ? String.valueOf(oaCOrderPersonals.get(i).getVehicleId()) : "");
                resultLists.add(orderListBean);
            }


            // 拼接城市信息
            if (CheckUtil.objIsNotEmpty(cityCodes)) {
                // 开始进行城市字典表查询
                List<OaSysArea> dictArea = this.getDictArea(OaSysArea.AD_CODE, cityCodes);
                // 开始进行城市字典的数据拼接
                for (int i = 0; i < resultLists.size(); i++) {
                    for (int j = 0; j < dictArea.size(); j++) {
                        if (CheckUtil.strIsNotEmpty(resultLists.get(i).getCityId()) && resultLists.get(i).getCityId().equals(dictArea.get(j).getAdCode())) {
                            resultLists.get(i).setCityStr(dictArea.get(j).getName());
                        }
                    }
                }
            }

            // 拼接车牌信息
            if (CheckUtil.objIsNotEmpty(vehicleIds)) {
                QueryWrapper<OaSysVehicle> queryWrapperVehicleId = new QueryWrapper<>();
                queryWrapperVehicleId.in(OaSysVehicle.VEHICLE_ID, vehicleIds);
                queryWrapperVehicleId.select(OaSysVehicle.VEHICLE_ID, OaSysVehicle.VEH_NO);
                List<OaSysVehicle> oaSysVehicleList = oaSysVehicleMapper.selectList(queryWrapperVehicleId);
                for (int i = 0; i < resultLists.size(); i++) {
                    for (int j = 0; j < oaSysVehicleList.size(); j++) {
                        if (CheckUtil.strIsNotEmpty(resultLists.get(i).getVehicleId()) && resultLists.get(i).getVehicleId().equals(String.valueOf(oaSysVehicleList.get(j).getVehicleId()))) {
                            resultLists.get(i).setVehNo(oaSysVehicleList.get(j).getVehNo());
                        }
                    }
                }
            }

            // 拼接字典运力类型信息
            if (CheckUtil.objIsNotEmpty(dictList)) {
                for (int i = 0; i < resultLists.size(); i++) {
                    for (int j = 0; j < dictList.size(); j++) {
                        if (CheckUtil.strIsNotEmpty(resultLists.get(i).getVehicleType()) && dictList.get(j).getType().equals("require_level") && String.valueOf(oaCOrderPersonals.get(i).getVehicleType()).equals(dictList.get(j).getValue())) {
                            resultLists.get(i).setVehicleTypeStr(dictList.get(j).getLabel());
                        }
                    }
                }
            }
            return resultLists;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultLists;
    }

    /**
     * 查询第二组字段
     * oa_c_order_personal.driver_id,
     * oa_c_order_personal.order_status,
     * oa_c_order_personal.passenger_phone as user_phone,
     * oa_c_order_personal.cancel_reason
     *
     * @return
     */
    @Override
    public List<OrderList> orderInfoGroupTwo(OrderList orderList,List<Long> offices) {
        // 返回的结果集
        List<OrderList> resultLists = new ArrayList<>();
        try {
            QueryWrapper<OaCOrderPersonal> queryWrapper = this.findCondition(orderList);
            queryWrapper.select(OaCOrderPersonal.ORDER_NO, OaCOrderPersonal.DRIVER_ID, OaCOrderPersonal.ORDER_STATUS, OaCOrderPersonal.PASSENGER_PHONE, OaCOrderPersonal.CANCEL_REASON);
            queryWrapper.in(OaCOrderPersonal.OFFICE_ID,offices);
            //防止预约时间一致时排序混乱
            queryWrapper.orderByDesc(OaCOrderPersonal.PERSONAL_ID);
            List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryWrapper);
            // 创建系统字典表in查询的List
            List<String> dictValues = new ArrayList<>();
            dictValues.add("order_status");
            dictValues.add("cancel_reason");
            // 开始进行系统字典表查询
            List<OaSysDict> dictList = this.getDictList(OaSysDict.TYPE, dictValues);

            List<String> dUserList = new ArrayList<>();
            for (int i = 0; i < oaCOrderPersonals.size(); i++) {
                OrderList orderListBean = new OrderList();
                orderListBean.setOrderNo(oaCOrderPersonals.get(i).getOrderNo() != null ? oaCOrderPersonals.get(i).getOrderNo() : "");
                orderListBean.setDriverId(oaCOrderPersonals.get(i).getDriverId() != null ? String.valueOf(oaCOrderPersonals.get(i).getDriverId()) : "");
                orderListBean.setOrderStatus(oaCOrderPersonals.get(i).getOrderStatus() != null ? String.valueOf(oaCOrderPersonals.get(i).getOrderStatus()) : "");
                orderListBean.setUserPhone(oaCOrderPersonals.get(i).getPassengerPhone() != null ? String.valueOf(oaCOrderPersonals.get(i).getPassengerPhone()) : "");
                orderListBean.setCancelReason(oaCOrderPersonals.get(i).getCancelReason() != null ? String.valueOf(oaCOrderPersonals.get(i).getCancelReason()) : "");
                dUserList.add(String.valueOf(oaCOrderPersonals.get(i).getDriverId() != null ? String.valueOf(oaCOrderPersonals.get(i).getDriverId()) : ""));
                resultLists.add(orderListBean);
            }

            // 拼接字典运力类型信息
            if (CheckUtil.objIsNotEmpty(dictList)) {
                for (int i = 0; i < resultLists.size(); i++) {
                    for (int j = 0; j < dictList.size(); j++) {
                        if (CheckUtil.strIsNotEmpty(resultLists.get(i).getOrderStatus()) && dictList.get(j).getType().equals("order_status") && String.valueOf(oaCOrderPersonals.get(i).getOrderStatus()).equals(dictList.get(j).getValue())) {
                            resultLists.get(i).setOrderStatusStr(dictList.get(j).getLabel());
                        }
                        if (CheckUtil.strIsNotEmpty(resultLists.get(i).getCancelReason()) && dictList.get(j).getType().equals("cancel_reason") && oaCOrderPersonals.get(i).getCancelReason().equals(dictList.get(j).getValue())) {
                            resultLists.get(i).setCancelReasonStr(dictList.get(j).getLabel());
                        }
                    }
                }
            }

            // 拼接司机信息
            if (CheckUtil.objIsNotEmpty(dUserList)) {
                QueryWrapper<OaDUser> dUserQueryWrapper = new QueryWrapper<>();
                dUserQueryWrapper.in(OaDUser.DRIVER_ID, dUserList);
                dUserQueryWrapper.select(OaDUser.DRIVER_ID, OaDUser.DRIVER_NAME, OaDUser.DRIVER_PHONE);
                List<OaDUser> oaDUserList = oaDUserMapper.selectList(dUserQueryWrapper);
                for (int i = 0; i < resultLists.size(); i++) {
                    for (int j = 0; j < oaDUserList.size(); j++) {
                        if (null != resultLists.get(i).getDriverId() && resultLists.get(i).getDriverId().equals(String.valueOf(oaDUserList.get(j).getDriverId()))) {
                            resultLists.get(i).setDriverName(oaDUserList.get(j).getDriverName());
                            resultLists.get(i).setDriverPhone(oaDUserList.get(j).getDriverPhone());
                        }
                    }
                }
            }
            /*
            update by:sunzheg ; Time : 2021-03-10
            拼接司机车队信息  vehicleTeam
             */
            if (CheckUtil.objIsNotEmpty(dUserList)) {
                QueryWrapper<OaDUserInfo> dUserQueryWrapper = new QueryWrapper<>();
                dUserQueryWrapper.in(OaDUserInfo.DRIVER_ID, dUserList);
                dUserQueryWrapper.select(OaDUserInfo.DRIVER_ID, OaDUserInfo.VEHICLE_TEAM);
                List<OaDUserInfo> oaDUserInfoList = oaDUserInfoMapper.selectList(dUserQueryWrapper);
                for (int i = 0; i < resultLists.size(); i++) {
                    for (int j = 0; j < oaDUserInfoList.size(); j++) {
                        if (null != resultLists.get(i).getDriverId() && resultLists.get(i).getDriverId().equals(String.valueOf(oaDUserInfoList.get(j).getDriverId()))) {
                            resultLists.get(i).setVehicleTeam(oaDUserInfoList.get(j).getVehicleTeam());
                        }
                    }
                }
            }
            return resultLists;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultLists;
    }

    /**
     * 查询第三组字段
     * oa_c_order_personal.didi_order_id,
     * oa_c_order_personal.start_address,
     * oa_c_order_personal.end_address,
     * oa_c_order_personal.actual_fee,
     *
     * @return
     */
    @Override
    public List<OrderList> orderInfoGroupThree(OrderList orderList,List<Long> offices) {
        List<OrderList> resultLists = new ArrayList<>();
        try {
            QueryWrapper<OaCOrderPersonal> queryWrapper = this.findCondition(orderList);
            //queryWrapper.select(OaCOrderPersonal.ORDER_NO, OaCOrderPersonal.START_ADDRESS, OaCOrderPersonal.END_ADDRESS, OaCOrderPersonal.ACTUAL_FEE);
            queryWrapper.select(OaCOrderPersonal.START_ADDRESS, OaCOrderPersonal.END_ADDRESS, OaCOrderPersonal.ACTUAL_FEE);
            queryWrapper.in(OaCOrderPersonal.OFFICE_ID,offices);
            //防止预约时间一致时排序混乱
            queryWrapper.orderByDesc(OaCOrderPersonal.PERSONAL_ID);
            List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryWrapper);
            for (int i = 0; i < oaCOrderPersonals.size(); i++) {
                OrderList orderListBean = new OrderList();
                orderListBean.setOrderNo(oaCOrderPersonals.get(i).getOrderNo() != null ? oaCOrderPersonals.get(i).getOrderNo() : "");
                orderListBean.setStartAddress(oaCOrderPersonals.get(i).getStartAddress() != null ? oaCOrderPersonals.get(i).getStartAddress() : "");
                orderListBean.setEndAddress(oaCOrderPersonals.get(i).getEndAddress() != null ? oaCOrderPersonals.get(i).getEndAddress() : "");
                orderListBean.setActualFee(oaCOrderPersonals.get(i).getActualFee() != null ? String.valueOf(oaCOrderPersonals.get(i).getActualFee()) : "");
                resultLists.add(orderListBean);
            }
            return resultLists;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultLists;
    }

    /**
     * 查询第四组字段
     * oa_c_order_personal.total_fee,
     * oa_c_order_personal.start_fee,
     * oa_c_order_personal.duration_fee,
     * oa_c_order_personal.mileage_fee,
     *
     * @return
     */
    @Override
    public List<OrderList> orderInfoGroupFour(OrderList orderList,List<Long> offices) {
        List<OrderList> resultLists = new ArrayList<>();
        try {
            QueryWrapper<OaCOrderPersonal> queryWrapper = this.findCondition(orderList);
            //queryWrapper.select(OaCOrderPersonal.ORDER_NO, OaCOrderPersonal.DISTANCE_FEE, OaCOrderPersonal.START_FEE, OaCOrderPersonal.DURATION_FEE, OaCOrderPersonal.MILEAGE_FEE);
            queryWrapper.select(OaCOrderPersonal.DISTANCE_FEE, OaCOrderPersonal.START_FEE, OaCOrderPersonal.DURATION_FEE, OaCOrderPersonal.MILEAGE_FEE);
            queryWrapper.in(OaCOrderPersonal.OFFICE_ID,offices);
            //防止预约时间一致时排序混乱
            queryWrapper.orderByDesc(OaCOrderPersonal.PERSONAL_ID);
            List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryWrapper);
            for (int i = 0; i < oaCOrderPersonals.size(); i++) {
                OrderList orderListBean = new OrderList();
                orderListBean.setOrderNo(oaCOrderPersonals.get(i).getOrderNo() != null ? oaCOrderPersonals.get(i).getOrderNo() : "");
                orderListBean.setDistanceFee(oaCOrderPersonals.get(i).getDistanceFee() != null ? oaCOrderPersonals.get(i).getDistanceFee() : BigDecimal.valueOf(0));
                orderListBean.setStartFee(oaCOrderPersonals.get(i).getStartFee() != null ? oaCOrderPersonals.get(i).getStartFee() : BigDecimal.valueOf(0));
                orderListBean.setDurationFee(oaCOrderPersonals.get(i).getDurationFee() != null ? oaCOrderPersonals.get(i).getDurationFee() : BigDecimal.valueOf(0));
                orderListBean.setMileageFee(oaCOrderPersonals.get(i).getMileageFee() != null ? oaCOrderPersonals.get(i).getMileageFee() : BigDecimal.valueOf(0));
                resultLists.add(orderListBean);
            }
            for (int i = 0; i < resultLists.size(); i++) {
                if (CheckUtil.objIsNotEmpty(resultLists.get(i).getMileageFee())) {
                    resultLists.get(i).setTravelCost(resultLists.get(i).getTravelCost().add(resultLists.get(i).getMileageFee()));
                }
                if (CheckUtil.objIsNotEmpty(resultLists.get(i).getDurationFee())) {
                    resultLists.get(i).setTravelCost(resultLists.get(i).getTravelCost().add(resultLists.get(i).getDurationFee()));
                }
                if (CheckUtil.objIsNotEmpty(resultLists.get(i).getDistanceFee())) {
                    resultLists.get(i).setTravelCost(resultLists.get(i).getTravelCost().add(resultLists.get(i).getDistanceFee()));
                }
                if (CheckUtil.objIsNotEmpty(resultLists.get(i).getStartFee())) {
                    resultLists.get(i).setTravelCost(resultLists.get(i).getTravelCost().add(resultLists.get(i).getStartFee()));
                }
            }
            return resultLists;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultLists;

    }

    /**
     * 查询第五组字段
     * oa_c_order_personal.distance_fee,
     * date_format(oa_c_order_personal.order_time, '%Y-%m-%d %H:%i:%s' ) as order_time,
     * date_format(oa_c_order_personal.arrive_time, '%Y-%m-%d %H:%i:%s' ) as arrive_time ,
     * date_format(oa_c_order_personal.notarize_time, '%Y-%m-%d %H:%i:%s' ) as notarize_time
     *
     * @return
     */
    @Override
    public List<OrderList> orderInfoGroupFive(OrderList orderList,List<Long> offices) {
        List<OrderList> resultLists = new ArrayList<>();
        try {
            QueryWrapper<OaCOrderPersonal> queryWrapper = this.findCondition(orderList);
            //queryWrapper.select(OaCOrderPersonal.ORDER_NO, OaCOrderPersonal.DIDI_ORDER_ID,OaCOrderPersonal.TOTAL_FEE, OaCOrderPersonal.CREATE_TIME, OaCOrderPersonal.ARRIVE_TIME, OaCOrderPersonal.NOTARIZE_TIME);
            queryWrapper.select(OaCOrderPersonal.DIDI_ORDER_ID, OaCOrderPersonal.TOTAL_FEE, OaCOrderPersonal.APPOINTMENT, OaCOrderPersonal.ARRIVE_TIME, OaCOrderPersonal.NOTARIZE_TIME);
            queryWrapper.in(OaCOrderPersonal.OFFICE_ID,offices);
            //防止预约时间一致时排序混乱
            queryWrapper.orderByDesc(OaCOrderPersonal.PERSONAL_ID);
            List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryWrapper);
            for (int i = 0; i < oaCOrderPersonals.size(); i++) {
                OrderList orderListBean = new OrderList();
                orderListBean.setOrderNo(oaCOrderPersonals.get(i).getOrderNo() != null ? oaCOrderPersonals.get(i).getOrderNo() : "");
                orderListBean.setDidiOrderId(oaCOrderPersonals.get(i).getDidiOrderId() != null ? oaCOrderPersonals.get(i).getDidiOrderId() : "");
                orderListBean.setTotalFee(oaCOrderPersonals.get(i).getTotalFee() != null ? String.valueOf(oaCOrderPersonals.get(i).getTotalFee()) : "");
                //orderListBean.setCreateTime(oaCOrderPersonals.get(i).getCreateTime() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getCreateTime(), dateFormat) : "");
                orderListBean.setCreateTime(oaCOrderPersonals.get(i).getAppointment() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getAppointment(), dateFormat) : "");
                orderListBean.setArriveTime(oaCOrderPersonals.get(i).getArriveTime() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getArriveTime(), dateFormat) : "");
                orderListBean.setInitiateCollectionTime(oaCOrderPersonals.get(i).getArriveTime() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getArriveTime(), dateFormat) : "");
                orderListBean.setNotarizeTime(oaCOrderPersonals.get(i).getNotarizeTime() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getNotarizeTime(), dateFormat) : "");
                resultLists.add(orderListBean);
            }
            return resultLists;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultLists;
    }

    /**
     * 查询第六组字段
     * date_format(oa_c_order_personal.meet_passenger_time, '%Y-%m-%d %H:%i:%s' ) as meet_passenger_time,
     * date_format(oa_c_order_personal.passenger_pay_time, '%Y-%m-%d %H:%i:%s' ) as passenger_pay_time,
     * date_format(oa_c_order_personal.cancel_order_time, '%Y-%m-%d %H:%i:%s' ) as cancel_order_time
     *
     * @return
     */
    @Override
    public List<OrderList> orderInfoGroupSix(OrderList orderList,List<Long> offices) {
        List<OrderList> resultLists = new ArrayList<>();
        try {
            QueryWrapper<OaCOrderPersonal> queryWrapper = this.findCondition(orderList);
            queryWrapper.select(OaCOrderPersonal.ORDER_NO, OaCOrderPersonal.ARRIVE_MEET_PASSENGER_TIME, OaCOrderPersonal.PASSENGER_PAY_TIME, OaCOrderPersonal.CANCEL_ORDER_TIME,OaCOrderPersonal.OFFICE_ID,OaCOrderPersonal.APPOINTMENT,OaCOrderPersonal.MILAGE_DISTANCE);
            queryWrapper.in(OaCOrderPersonal.OFFICE_ID,offices);
            //防止预约时间一致时排序混乱
            queryWrapper.orderByDesc(OaCOrderPersonal.PERSONAL_ID);
            List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryWrapper);
            List<String> orderNoList = new ArrayList<>();
            for (int i = 0; i < oaCOrderPersonals.size(); i++) {
                OrderList orderListBean = new OrderList();
                if(oaCOrderPersonals.get(i).getOfficeId() != null){
                    List<OaSysUser> oaSysUserList = oaSysUserMapper.selectList(Qw.create().eq(OaSysUser.OFFICE_ID,Long.parseLong(oaCOrderPersonals.get(i).getOfficeId())));
                    if(oaSysUserList.size() > 0){
                        orderListBean.setOfficeName(oaSysUserList.get(0).getName());
                    }
                }
                orderNoList.add(oaCOrderPersonals.get(i).getOrderNo());
                orderListBean.setAppointmentTime(oaCOrderPersonals.get(i).getAppointment() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getAppointment(), dateFormat) : "");
                orderListBean.setOrderNo(oaCOrderPersonals.get(i).getOrderNo());
                orderListBean.setArriveMeetPassengerTime(oaCOrderPersonals.get(i).getArriveMeetPassengerTime() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getArriveMeetPassengerTime(), dateFormat) : "");
                orderListBean.setPassengerPayTime(oaCOrderPersonals.get(i).getPassengerPayTime() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getPassengerPayTime(), dateFormat) : "");
                orderListBean.setCancelOrderTime(oaCOrderPersonals.get(i).getCancelOrderTime() != null ? DateUtil.convertToStringCustom(oaCOrderPersonals.get(i).getCancelOrderTime(), dateFormat) : "");
                orderListBean.setMilageDistance(oaCOrderPersonals.get(i).getMilageDistance() != null ? oaCOrderPersonals.get(i).getMilageDistance().toString() : "0");
                resultLists.add(orderListBean);
            }

            if (CheckUtil.objIsNotEmpty(orderNoList)) {
                QueryWrapper<OaOrderOtherPrice> oaDOrderQueryWrapper = new QueryWrapper<>();
                oaDOrderQueryWrapper.in(OaDOrder.ORDER_NO, orderNoList);
                oaDOrderQueryWrapper.select(OaOrderOtherPrice.ORDER_NO, OaOrderOtherPrice.COST_AMOUNT);
                List<OaOrderOtherPrice> oaOrderOtherPriceList = oaOrderOtherPriceMapper.selectList(oaDOrderQueryWrapper);
                if (CheckUtil.objIsNotEmpty(oaOrderOtherPriceList)) {
                    for (int i = 0; i < resultLists.size(); i++) {
                        for (int j = 0; j < oaOrderOtherPriceList.size(); j++) {
                            if (CheckUtil.objIsNotEmpty(oaOrderOtherPriceList.get(j).getCostAmount()) && resultLists.get(i).getOrderNo().equals(oaOrderOtherPriceList.get(j).getOrderNo())) {
                                resultLists.get(i).setAdditionalCost(resultLists.get(i).getAdditionalCost().add(oaOrderOtherPriceList.get(j).getCostAmount()));
                            }
                        }
                    }
                }
            }
            return resultLists;
        }catch (Exception e){
           e.printStackTrace();
        }
        return resultLists;
    }

    @Override
    public List<OrderList> orderInfoGroupSeven(OrderList orderList,List<Long> offices) {
        List<OrderList> resultLists = new ArrayList<>();
        try {
            QueryWrapper<OaCOrderPersonal> queryWrapper = this.findCondition(orderList);
            queryWrapper.select(OaCOrderPersonal.ORDER_NO);
            queryWrapper.in(OaCOrderPersonal.OFFICE_ID,offices);
            //防止预约时间一致时排序混乱
            queryWrapper.orderByDesc(OaCOrderPersonal.PERSONAL_ID);
            List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryWrapper);
            for (int i = 0; i < oaCOrderPersonals.size(); i++) {
                OrderList orderListBean = new OrderList();
                OaSysOrderDetails oaSysOrderDetails = oaSysOrderDetailsMapper.selectOne(Qw.create().eq(OaSysOrderDetails.ORDER_NO,oaCOrderPersonals.get(i).getOrderNo()));
                if(CheckUtil.objIsNotEmpty(oaSysOrderDetails)){
                    orderListBean.setMeetCTime(oaSysOrderDetails.getMeetCTime() != null ? DateUtil.convertToStringCustom(oaSysOrderDetails.getMeetCTime(), dateFormat) : "");
                    orderListBean.setDriverInPlaceTime(oaSysOrderDetails.getDriverInPlaceTime() != null ? DateUtil.convertToStringCustom(oaSysOrderDetails.getDriverInPlaceTime(), dateFormat) : "");
                    orderListBean.setStartJourneyTime(oaSysOrderDetails.getStartJourneyTime() != null ? DateUtil.convertToStringCustom(oaSysOrderDetails.getStartJourneyTime(), dateFormat) : "");
                    orderListBean.setEndJourneyTime(oaSysOrderDetails.getEndJourneyTime() != null ? DateUtil.convertToStringCustom(oaSysOrderDetails.getEndJourneyTime(), dateFormat) : "");
                }
                resultLists.add(orderListBean);
            }

            return resultLists;
        }catch (Exception e){
            e.printStackTrace();
        }
        return resultLists;
    }

    @Override
    public List<OrderList> allOrderInfo(OrderList orderList, List<Long> offices) {
        return null;
    }
}
